﻿using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace WSU.ChekaParallel.TestTask
{
    static class TestLongRunTask
    {
        public static void TestMain()
        {
            BlockingCollection<string> queue = new BlockingCollection<string>();

            Task consumerTask = Task.Factory.StartNew(() =>
            {
                foreach (string msg in queue.GetConsumingEnumerable())
                {
                    Console.WriteLine("'{0}' has {1} characters", msg, msg.Length);
                }
                Console.WriteLine("*********** consumer task completes");
            }, TaskCreationOptions.LongRunning);

            while (true)
            {
                string input = Console.ReadLine();
                if (input.Equals("exit", StringComparison.OrdinalIgnoreCase))
                {
                    queue.CompleteAdding();
                    break;
                }
                else
                    queue.Add(input);
            }// while

            consumerTask.Wait();
        }// TestMain
    }
}
